package com.alibaba.cloud.ai.example.manus.SelfTool;

import com.alibaba.cloud.ai.example.manus.llm.LlmService;
import com.alibaba.cloud.ai.example.manus.tool.AbstractBaseTool;
import com.alibaba.cloud.ai.example.manus.tool.code.ToolExecuteResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class MyWeatherTool extends AbstractBaseTool<MyWeatherTool.WeatherInput>{
    private static final Logger log = LoggerFactory.getLogger(MyWeatherTool.class);
    private static String PARAMETERS = """
			{
			    "type": "object",
			    "properties": {
			        "question": {
			            "type": "string",
			            "description": "(required) use natural language to get the weather condition."
			        }
			    },
			    "required": ["question"]
			}
			""";

    private static final String name = "weather_tool";

    private static final String description = """
			the best tool for getting weather condition
			""";


    /**
     * Internal input class for defining input parameters of the weather tool
     */
    public static class WeatherInput {

        @com.fasterxml.jackson.annotation.JsonProperty("question")
        private String question;

        public WeatherInput() {
        }

        public WeatherInput(String question) {
            this.question = question;
        }

        public String getQuestion() {
            return question;
        }

        public void setQuestion(String question) {
            this.question = question;
        }
    }

    @Override
    public ToolExecuteResult run(WeatherInput input) {
        log.info("天气工具被调用成功");
        return new ToolExecuteResult("今天的天气是晴天");
    }

    @Override
    public String getServiceGroup() {
        return "default-service-group";
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public String getParameters() {
        return PARAMETERS;
    }

    @Override
    public Class<WeatherInput> getInputType() {
        return WeatherInput.class;
    }

    @Override
    public String getCurrentToolStateString() {
        return String.format("""
				            Current File Operation State:
				            - Working Directory:
				%s

				            - Last File Operation:
				%s

				            - Last Operation Result:
				%s

				            """, new File("").getAbsolutePath(),
                lastFilePath.isEmpty() ? "No file loaded yet"
                        : String.format("Load %s file from: %s", lastFileType, lastFilePath),
                lastOperationResult.isEmpty() ? "No operation performed yet" : lastOperationResult);
    }

    @Override
    public void cleanup(String planId) {
        //do nothing
    }
    private String lastFilePath = "";

    private String lastOperationResult = "";

    private String lastFileType = "";
}
